function t(t) {
    this.selfOpenId = "", this.ctx = t, this.left = 0, this.top = 0, this.width = 1e3, 
    this.height = 1e3, this.sortedRankData = [], this.myInfo = {}, this.opened = !1, 
    this.currentScore = 0, this.scoreFont = "arial";
}

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = t;

var e = function(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}(require("./utils.js"));

t.prototype.logicHandle = function(t) {
    var e = this;
    this.opened = !0, this.currentScore = t.score, wx.getFriendCloudStorage({
        shareTicket: t.shareTicket,
        keyList: [ "score" ],
        success: function(a) {
            e.sortRankList(a.data), e.drawRankList(t);
        }
    });
}, t.prototype.setOpenId = function(t) {
    if (this.selfOpenId = t, this.opened) {
        if (this.sortedRankData.length <= 0) return;
        this.getMyInfo(), this.drawRankList();
    }
}, t.prototype.sortRankList = function(t) {
    var a = e.default.transRankData(t);
    this.sortedRankData = e.default.quickSortByScore(a);
}, t.prototype.getMyInfo = function() {
    for (var t = -1, e = 0; e < this.sortedRankData.length && !(this.sortedRankData[e].score <= this.currentScore); e++) t = e;
    if (-1 == t) {
        for (e = 0; e < this.sortedRankData.length; e++) if (this.sortedRankData[e].openId == this.selfOpenId) {
            this.myInfo.rank = e + 1, this.myInfo.avatarUrl = this.sortedRankData[e].avatarUrl, 
            this.myInfo.nickname = this.sortedRankData[e].nickname, this.myInfo.score = this.currentScore;
            break;
        }
    } else console.log("index:" + t), this.myInfo.rank = t + 1, this.myInfo.avatarUrl = this.sortedRankData[t].avatarUrl, 
    this.myInfo.nickname = this.sortedRankData[t].nickname, this.myInfo.score = this.sortedRankData[t].score;
}, t.prototype.drawRankList = function(t) {
    this.getMyInfo();
    this.ctx;
    this.left = t.left, this.top = t.top, this.width = t.width, this.height = t.height, 
    this.sortedRankData.length <= 0 || this.drawSinglePage(this.myInfo);
}, t.prototype.drawSinglePage = function(t) {
    "" !== this.selfOpenId && (this.ctx.clearRect(0, 0, e.default.screenWidth, e.default.screenHeight), 
    this.drawElement(t, this.left + 312, this.top, 312, 100));
}, t.prototype.closedClear = function() {
    this.opened = !1;
    var t = this.sortedRankData.length;
    if (!(t <= 0)) {
        var a = this.ctx, s = this.myInfo.rank - 2;
        s < 0 && (s = this.myInfo.rank - 1);
        var i = this.myInfo.rank;
        i >= t && (i = t - 1);
        for (var n = s; n < i; n++) {
            var r = this.sortedRankData[n];
            r.img && (r.img.onload = null);
        }
        a.clearRect(0, 0, e.default.screenWidth, e.default.screenHeight);
    }
}, t.prototype.drawElement = function(t, e, a, s, i) {
    var n = 400, r = "80px " + this.scoreFont, o = this.ctx, h = wx.createImage();
    h.src = t.avatarUrl, t.img = h, h.onload = function() {
        o.drawImage(t.img, e + 100, a + 44, 124, 124), t.loaded = !0;
    }, o.fillStyle = "#fff", o.font = r, o.drawImage(t.img, e + 100, a + 44, 124, 124), 
    n -= o.measureText(t.score).width / 2, o.fillText(t.score, e + n, a + 140);
};